﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartCity.ProcessEngine.Api.Write.Application.Command.EventHandling;
using SmartCity.ProcessEngine.ErrorCode;

namespace SmartCity.ProcessEngine.Api.Write.Controllers
{
    /// <summary>
    /// 流程实例控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class InstanceController : ControllerBase
    {
        private readonly IMediator mediator;

        /// <summary>
        /// 通过构造函数注入中介者组件
        /// </summary>
        public InstanceController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 选择好流程后,新建一个流程实例
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateInstance(CreateInstanceCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 审批流程
        /// </summary>
        /// <param name="request">审批流程的参数</param>
        /// <returns>响应包装类包装的审批操作结果</returns>
        [HttpPost]
        public async Task<ApiResult<int>> ExamineInstanceNode(ExeInstanceNodeCommand request) {
            return await mediator.Send(request);
        } 
    }
}
